<%--
  Created by IntelliJ IDEA.
  User: zk
  Date: 2017/11/9
  Time: 10:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<blockquote class="layui-elem-quote">${title}</blockquote>
<a href="${ctx}/sys/user/form" class="layui-btn"><i class="layui-icon">&#xe608;</i>新增用户</a>
<br>

<table class="layui-table" id="userList" lay-filter="userList" >
</table>
<script>

    var layer = layui.layer;
    <c:if test="${message ne null and message ne ''}">
    layer.msg('${message}',{anim: 1});
    </c:if>

    $(function(){
        var table = layui.table,
            form = layui.form;
        table.render({
            elem: '#userList' //指定原始表格元素选择器（推荐id选择器）
            ,cols: [[
                {field: 'name', title: '登录账号',edit:'text',align:'center'},
                {field: 'nickname', title: '昵称',edit:'text',align:'center'},
                {field: 'mobile', title: '手机号',edit:'text',align:'center'},
                {field: 'email', title: '邮箱',edit:'text',align:'center'},
                {field: 'loginFlag', title: '登录状态',align:'center',templet: '#loginFlag', unresize: true},
                {title: '操作',toolbar: '#operateCol',align:'center'}]] //设置表头
            ,data:${fns:toJson(list)}
            ,limit:10
        });

        table.on('tool(userList)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if(layEvent === 'edit'){ //编辑权限
                pjaxReq(ctx+'/sys/user/form?id='+data.id);
            } else if(layEvent === 'del'){ //删除
                delCustom('确定删除该用户吗？',ctx+'/sys/user/delete?id='+data.id);
            } else if(layEvent === 'save'){ //保存
                data.loginFlag = $("input[name='loginFlag']", obj.tr).val();
                ajaxPost('${ctx}/sys/user/saveResp',data,function(respData){
                    layui.layer.msg(respData,{anim: 1});
                });
            }
        });

        form.on('switch(loginFlag)', function(data){
            this.value = data.elem.checked?'0':'1';
        });
    });
</script>

<script type="text/html" id="operateCol">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit" data-pjax>编辑更多</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="save">保存</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" data-pjax>删除</a>
</script>

<script type="text/html" id="loginFlag">
    <input type="checkbox" name="loginFlag" value="{{d.loginFlag}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="loginFlag" {{ d.loginFlag == 0?'checked' : '' }}>
</script>